package com.songshuai.webapi.baseapi.dto.crmbase;

import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import lombok.Data;

@Data
public class BaseApiQueryResponse<T> {

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 返回信息描述
     */
    private String message;

    /**
     * 页数（分页查询时使用）
     */
    private long count;

    //总页数
    private long countPage;

    public BaseApiQueryResponse() {
        code = ResultStatus.SUCCESS.getErrorCode();
        message = ResultStatus.SUCCESS.getErrorMsg();
    }

    public BaseApiQueryResponse(ResultStatus resultStatus) {
        code = resultStatus.getErrorCode();
        message = resultStatus.getErrorMsg();
    }

    public BaseApiQueryResponse(int code,String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> BaseApiQueryResponse setResData(T data) {
        BaseApiQueryResponse<T> res = new BaseApiQueryResponse<>();
        res.setData(data);
        return res;
    }

    public static <T> BaseApiQueryResponse setResData(T data,long count, long countPage) {
        BaseApiQueryResponse<T> res = new BaseApiQueryResponse<>();
        res.setData(data);
        res.setCount(count);
        res.setCountPage(countPage);

        return res;
    }

    public static <T> BaseApiQueryResponse setResData(T data,long count) {
        BaseApiQueryResponse<T> res = new BaseApiQueryResponse<>();
        res.setData(data);
        res.setCount(count);
        return res;
    }

    public static <T> BaseApiQueryResponse setResData(T data, ResultStatus resultStatus) {
        BaseApiQueryResponse<T> res = new BaseApiQueryResponse<>();
        res.setData(data);
        res.setCode(resultStatus.getErrorCode());
        res.setMessage(resultStatus.getErrorMsg());
        return res;
    }

    public static <T> BaseApiQueryResponse setResData(T data, ResultStatus resultStatus, String msg) {
        BaseApiQueryResponse<T> res = new BaseApiQueryResponse<>();
        res.setData(data);
        res.setCode(resultStatus.getErrorCode());
        res.setMessage(msg);
        return res;
    }

    public static <T> BaseApiQueryResponse setResData(T data, Integer errCode, String msg) {
        BaseApiQueryResponse<T> res = new BaseApiQueryResponse<>();
        res.setData(data);
        res.setCode(errCode);
        res.setMessage(msg);
        return res;
    }


}
